/*
fn largest<T: PartialOrd>(list: &[T]) -> &T {
	let mut largest = &list[0];

	for item in list.iter() {
		if item > largest {
			largest = item;
		}
	}

	&largest
}*/

fn largest<T: PartialOrd + Copy>(list: &[T]) -> T {
	let mut largest = list[0];
	
	for item in list.iter() {  //前面的&表示什么
		if *item > largest {
			largest = *item;
		}
	}
	largest
}

fn main() {
	let number_list = vec![34, 50, 25, 100, 65];

	let result = largest(&number_list);
	println!("The largest number is {}", result);

	let char_list = vec!['y', 'm', 'a', 'q'];
	let result = largest(&char_list);
	println!("The largest char is {}", result);
	
	let str_list = vec!["abc", "def", "ghi"];
	let result = largest(&str_list);
	println!("The largest char is {}", result);

	let a = 2;
	let b = "cjb";
	let c = "abc";
	println!{"a: {}, b: {}, c: {}", a, b, &c};

	let v = vec![1, 2, 3, 4, 5];
	for i in &v {
		println!("{}", *i);
	}

	let y = &mut 9;
	*y = 11;
	println!{"y: {}", y};

	fn foo(s: &str) {
		println!("{}", s);
	}
	let owned = "Hello".to_string();

	foo(&owned);

}
